<?php

namespace App\Exports;

use App\Models\Product;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;

class ProductExport implements WithHeadings, FromQuery, WithStrictNullComparison
{
    use Exportable;

    public function headings(): array
    {
        return [
            'id',
            'name',
            'brand_id',
            'brand',
            'picked_count',
            'created_at',
            'updated_at',
        ];
    }

    public function query()
    {
        return Product::query()->leftJoin('brands', 'products.brand_id', '=', 'brands.id')
            ->selectRaw('products.id, products.name, products.brand_id, brands.name as brand, 
        products.picked_count, products.created_at, products.updated_at');
    }
}
